package com.cpe.web.controller.teacher;

import static com.sql.data.response.CommonRespCode.EXCEPTION;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.cpe.data.domain.teacher.Teacher;
import com.cpe.data.domain.teacher.TeacherQuery;
import com.cpe.repository.mapper.teacher.TeacherMapper;
import com.cpe.web.controller.AbstractController;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sql.data.response.JsonResponse;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestController
@RequestMapping("/teachers")
public class TeacherController extends AbstractController {

	@Resource
	private TeacherMapper teacherMapper;

	@RequestMapping(method = RequestMethod.GET)
	public JsonResponse getPage(TeacherQuery query) {
		try {
			PageHelper.startPage(query.pageWhitoutOrder());
			List<Teacher> teachers = teacherMapper.findAll();
			return JsonResponse.ok(new PageInfo<>(teachers));
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			return JsonResponse.custom(EXCEPTION);
		}
	}
}
